﻿using System;
using personalplaner.core.errorhandling;

namespace personalplaner.servicemodel.common
{
	public interface IErrorLoger
	{
		/// <summary>
		/// Logs an errormessage to a xml file
		/// </summary>
		/// <param name="errortext"></param>
		void ToXML(string errortext);

		/// <summary>
		/// Logs an errormessage to a xml file
		/// </summary>
		/// <param name="caption"></param>
		/// <param name="location"></param>
		/// <param name="errorText"></param>
		void ToXML(string caption, string location, string errorText);

		/// <summary>
		/// Loggs a message/event to log.txt. UseLogger has to be true if the logger wants to be used
		/// </summary>
		/// <param name="messageType">type of message/title of message</param>
		/// <param name="message">message to logg</param>
		void LoggMessage(enMessageType messageType, string message);
	}

	public class ErrorLoger : IErrorLoger
	{
		/// <summary>
		/// Logs an errormessage to a xml file
		/// </summary>
		/// <param name="errortext"></param>
		public void ToXML(string errortext)
		{
			Logger.ToXML(errortext);
		}

		/// <summary>
		/// Logs an errormessage to a xml file
		/// </summary>
		/// <param name="caption"></param>
		/// <param name="location"></param>
		/// <param name="errorText"></param>
		public void ToXML(string caption, string location, string errorText)
		{
			Logger.ToXML(caption, location, errorText);
		}

		/// <summary>
        /// Loggs a message/event to log.txt. UseLogger has to be true if the logger wants to be used
        /// </summary>
        /// <param name="messageType">type of message/title of message</param>
        /// <param name="message">message to logg</param>
		public void LoggMessage(enMessageType messageType, string message)
		{
			var mt = (MessageType)Enum.Parse(typeof(MessageType), messageType.ToString());
			ActionLogger.LoggMessage(mt, message);
		}
	}

	public enum enMessageType { SQL, ODBC, ERROR, ODBC_ERROR, SQL_ERROR, USER_ERROR, USER_EVENT, SYSTEM_EVENT, DATA_EVENT, DATA_ERROR };
}
